/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fasea.search.documents;

import fasea.index.filehandler.FileHandlerException;
import fasea.ui.utils.ImageControl;
import java.text.DateFormat;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 *
 * @author WolframL
 */
public class ImageDocument extends Document {

    public ImageDocument(org.apache.lucene.document.Document document) {
        setDocument(document);
    }

    @Override
    public Icon getThumbnail() throws FileHandlerException {
        byte[] bytes = document.getBinaryValue("thumbnail");
        if (bytes != null) {
            return new ImageIcon(bytes);
        } else {
            return super.getThumbnail();
        }
    }

    @Override
    public String getFragment() {
        StringBuilder fragmentBuilder = new StringBuilder();
        String lastModified = DateFormat.getDateInstance().format(getLastModified());

        fragmentBuilder.append("<font face=\"arial,sans-serif\" SIZE=\"3\" COLOR=\"#96b1cb\">");
        fragmentBuilder.append("Last Modified: ").append(lastModified).append("<br />");
        fragmentBuilder.append("Dimensions: ").append(document.get("width")).append(" x ").append(document.get("height"));
        fragmentBuilder.append("</font>");
        return fragmentBuilder.toString();
    }
}
